package com.ruoyi.web.controller.business;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.BAssist;
import com.ruoyi.system.domain.vo.BAssistVo;
import com.ruoyi.system.service.BAssistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;

/**
 * 指南辅助
 * @author yangxz
 **/
@RestController
@RequestMapping("/business/assist")
public class AssistController extends BaseController {

    @Autowired
    private BAssistService assistService;


    /**
     * 获取指南辅助列表
     */
    @PreAuthorize("@ss.hasPermi('dict:assist:list')")
    @GetMapping("/list")
    public TableDataInfo list(BAssist bAssist)
    {
        startPage();
        List<BAssistVo> list = assistService.selectAssistList(bAssist);
        return getDataTable(list);
    }

    /**
     * 根据Id获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('dict:assist:query')")
    @GetMapping(value = "/{assitId}")
    public AjaxResult getInfo(@PathVariable Long assitId) {
        BAssistVo assistVo = assistService.selectAssistById(assitId);
        return success(assistVo);
    }

    /**
     * 新增指南辅助
     */
    @PreAuthorize("@ss.hasPermi('dict:assist:add')")
    @Log(title = "新增指南辅助", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BAssist assist)
    {
        assist.setCreateBy(getUsername());
        assist.setCreateTime(new Date());
        return toAjax(assistService.save(assist));
    }

    /**
     * 修改指南辅助
     */
    @PreAuthorize("@ss.hasPermi('dict:assist:edit')")
    @Log(title = "修改指南辅助", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BAssist assist){
        assist.setUpdateBy(SecurityUtils.getUsername());
        assist.setUpdateTime(new Date());
        return toAjax(assistService.updateById(assist));
    }

    /**
     * 删除指南辅助
     */
    @PreAuthorize("@ss.hasPermi('dict:assist:remove')")
    @Log(title = "删除指南辅助", businessType = BusinessType.DELETE)
    @DeleteMapping("/{assistIds}")
    public AjaxResult remove(@PathVariable Long[] assistIds)
    {
        return toAjax(assistService.deleteAssistByIds(assistIds));
    }

}
